﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.AspNetCore.Mvc.Rendering;
using HuaweiCloud.Dotnet.Samples.ESports.Dbs;
using HuaweiCloud.Dotnet.Samples.ESports.Entities;
using HuaweiCloud.Dotnet.Samples.ESports.Services;

namespace HuaweiCloud.Dotnet.Samples.ESports.Pages.Steps
{
    public class CreateModel : PageModel
    {
        private readonly IStepAppService _service;

        public CreateModel(IStepAppService service)
        {
            _service = service;
        }

        public IActionResult OnGet()
        {
            return Page();
        }

        [BindProperty]
        public Step Step { get; set; } = new Step(String.Empty, DateTime.Now, 0);
        

        // To protect from overposting attacks, see https://aka.ms/RazorPagesCRUD
        public async Task<IActionResult> OnPostAsync()
        {
            await _service.AddAsync(Step);

            return RedirectToPage("./Index");
        }
    }
}
